package com.wan.util;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

public class SplitUtil {
    public static final String COMMA_SEPARATOR = ",";

    public static String concat(Iterable<String> iterable,CharSequence separator){
        StringBuilder builder = new StringBuilder();
        Iterator<String> iterator = iterable.iterator();
        while (iterator.hasNext()){
            String next = iterator.next();
            builder.append(next);
            if(iterator.hasNext()){
                builder.append(separator);
            }
        }
        return builder.toString();
    }

    public static String concat(Iterable<String> iterable){
        return concat(iterable,COMMA_SEPARATOR);
    }

    public static String concat(CharSequence separator,String...arr){
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < arr.length; i++) {
            builder.append(arr[i]);
            if(i != arr.length - 1){
                builder.append(separator);
            }
        }
        return builder.toString();
    }

    public static String concat(String...arr){
        return concat(COMMA_SEPARATOR,arr);
    }

    public static void main(String[] args) {
        Set<String> strings = new HashSet<>();
        strings.add("aaa");
        strings.add("bbb");
        strings.add("ccc");
        String concat = concat(strings, ",\n");
        System.out.println(concat);
    }



}
